package tds.model1.version1;
/**
 * 
 * @Company 杭州先锋电子技术股份有限公司
 * @ClassName Calculation
 * @Description TODO(计算类)
 * @author tds
 * @Date 2019年1月3日 下午1:51:17
 * @version 1.0.0
 */
public class Calculation {
	public static double calculate(double param1, double param2, String operator){
		Operate operate = Operate.valueOperationOf(operator);
		if(operate == null){
			throw new RuntimeException("操作符不存在");
		}
		double result;
		switch (operate) {
			case ADD:
				result = param1 + param2;
				break;
			case SUB:
				result = param1 - param2;
				break;
			case MUL:
				result = param1 * param2;
				break;
			case DIV:
				if(param2 == 0){
					throw new RuntimeException("除数不能为0");
				}
				result = param1 / param2;
				break;
	
			default:
				throw new RuntimeException("未知的操作符");
		}
		return result;
	}
}
